
import gtk
from kiwi.ui.delegates import GladeDelegate
from kiwi.ui.gadgets import quit_if_last

from otica.views.acessoeditor import AcessoEditor
from otica.views.clienteeditor import ClienteEditor,ClienteSlave


class Principal(GladeDelegate):
    def __init__(self, usuario):
        GladeDelegate.__init__(self,
                          gladefile="principal",
                          delete_handler=self.delete_handler)
        
        self.tabela_aceso = {1:[self.restricao_de_acesso]}
        self.usuario = usuario
        self.usuarioExclui = False
        self._confgAcesso()
    
    def _confgAcesso(self):
        permissoes = self.usuario.permissoes
        ids_permissoes = [permissao.id for permissao in permissoes]
        if 2 in ids_permissoes:
            self.usuarioExclui = True
        for id,componentes in self.tabela_aceso.items():
            if id not in ids_permissoes:
                for componente in componentes:
                    componente.set_visible(False)
        
    
    def delete_handler(self, *args):
        gtk.main_quit()
    
    def show_restricao_de_acesso_editor(self, action):
        restricao = AcessoEditor(self.usuarioExclui)
        restricao.show_all()
        
    def show_clientes_editor(self, action):
        cliente = ClienteEditor(self.usuarioExclui)
        cliente.show_all()
        
    